import React, { PureComponent } from "react";
import { connect } from "react-redux";
import axios from "axios";

import {
  changeBannersAction,
  changeRecommendsAction,
} from "../store/actionCreators";

export class Category extends PureComponent {
  componentDidMount() {
    axios.get("http://123.207.32.32:8000/home/multidata").then((res) => {
      const { data } = res?.data || {};
      const { banner, recommend } = data || {};

      console.log("banner", banner);
      console.log("recommend", recommend);

      const { changeBanners, changeRecommends } = this.props;
      if (Array.isArray(banner?.list)) {
        changeBanners(banner.list);
      }
      if (Array.isArray(recommend?.list)) {
        changeRecommends(recommend.list);
      }
    });
  }
  render() {
    return <div>Category</div>;
  }
}

const mapDispatchToProps = (dispatch) => {
  return {
    changeBanners: (banners) => {
      dispatch(changeBannersAction(banners));
    },
    changeRecommends: (recommends) => {
      dispatch(changeRecommendsAction(recommends));
    },
  };
};

export default connect(null, mapDispatchToProps)(Category);
